<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title><!--{$lang.page.index.title}--></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/lay/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/lay/layui/index.css" media="all">
</head>
<body>

<div class="layui-fluid">
  <form name="addItem" method="post" lay-filter="component-form-group" class="layui-form">
    <input type="hidden" value="1" name="id">
    <input type="hidden" value="<!--{$datainfo.ids}-->" name="allids">
    <div class="layui-text-item" style="text-align: center;"><b><!--{$lang.page.table.auto}--><!--{$lang.page.table.regula}--></b></div>
    <div class="layui-form-item">
        <div class="layui-inline" id="submue"  style="width:50%;">
          <table class="layui-table" id="sharetable" lay-filter="table">
                <thead>
                    <tr>
                        <td height="40px"><!--{$lang.page.table.time}--><!--{$lang.page.table.set}--></td>
                        <td><!--{$lang.page.table.starttime}--></td>
                        <td><!--{$lang.page.table.endtime}--></td>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                    <td height="50px"><!--{$lang.page.public.select}--><!--{$lang.page.table.time}--></td>
                    <td><input type="text" name="starttime" value="<!--{$datainfo.starttime}-->" lay-verify="double" id="starttime" class="layui-input" /></td>
                    <td><input type="text" name="endtime" value="<!--{$datainfo.endtime}-->" lay-verify="double" id="endtime" class="layui-input" disabled/></td>
                    </tr>
                    <tr>
                    <td height="50px"><!--{$lang.page.table.notes}--></td>
                    <td colspan="2"><!--{$lang.page.table.contime}--></td>
                    </tr>
                  </tbody>
            </table>
        </div>
        <div class="layui-inline" >
          <table class="layui-table" lay-filter="table">
            <thead>
                    <tr>
                        <td height="40px"><!--{$lang.page.public.manger}--></td>
                        <td ></td>
                    </tr>
                </thead>
            <tr>
              <td height="50px"><!--{$lang.page.table.regula}--></td>
              <td>
                <div class="layui-form-item" style="margin-bottom: 0px">
                    <div class="layui-inline" style="margin-bottom: 0px">
                        <input type="text" name="ids" class="layui-input" value="">
                    </div>
                    <div class="layui-inline" style="margin-bottom: 0px">
                        <button class="layui-btn layui-btn-sm" type="button" id="checkrule"><!--{$lang.page.public.select}--></button>
                        <button type="button" id="crule" class="layui-btn layui-btn-disabled layui-btn-sm" lay-submit lay-filter="autorule" disabled><!--{$lang.page.table.confirm}--></button>
                    </div>
                  </div>
                </td>
            </tr>
            <tr>
              <td height="50px"><!--{$lang.page.table.editpara}--></td>
              <td>
                <div class="layui-form-item" style="margin-bottom: 0px">
                    <div class="layui-inline" style="margin-bottom: 0px">
                          <button type="button" id="cdata" class="layui-btn layui-btn-disabled layui-btn-sm" lay-submit lay-filter="submit" disabled><!--{$lang.page.public.submit}--></button>
                          <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onClick="xadmin.close();" ><!--{$lang.page.table.back}--></button>
                      </div>
                   </div>
                </td>
            </tr>
          </table>          
        </div>
    </div>
    
  </form>
</div>

  <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="datalist" lay-filter="datalist"></table>
            <script type="text/html" id="toolbartop">
                <button class="layui-btn layui-btn-sm" lay-event="redatalist"><!--{$lang.page.public.refresh}--></button>
                <button class="layui-btn layui-btn-sm" lay-event="reset"><!--{$lang.page.public.clear}--></button>
            </script>
            <script type="text/html" id="zizeng">{{d.LAY_TABLE_INDEX+1}}</script>
            <script type="text/html" id="bartool">
                <a class="layui-btn layui-btn-danger layui-btn-xs rdel" data-set="{{d.id}}"><!--{$lang.page.table.del}--></a>
            </script>
        </div>
    </div>
  </div>

<script src="/static/lay/layui/layui.js"></script>
<script type="text/javascript">
    layui.config({
       base: '/static/lay/' //静态资源所在路径
    }).extend({
         roleper:'lib/roleper'
         , xadmin:'lib/xadmin'
         , lang:'lib/lang'
       }).use(['roleper', 'xadmin', 'table', 'form', 'laydate', 'lang'], function () {

            var $ = layui.$
            , form = layui.form
            , table = layui.table
            , roleper = layui.roleper
            , toolbar = roleper.showtool({mid:23,per:[{sys:'rdel'}]}) ? false : true; //根据权限是否显示操作列
            var laydate = layui.laydate;
            var lang=layui.lang.init();
            form.render(null, 'component-form-group');
            form.verify({
              double:function(value){
                if(value.length<1){
                  return "<!--{$lang.page.table.set}--> <!--{$lang.page.table.time}-->"
                }
              }
            });
            var endDateMin = ''; // 结束时间的最小值
            // 开始时间选择器
            laydate.render({
              elem: '#starttime', // 指定元素
              type: 'time', // 只选择时间
              done: function(value, date){
                  endDateMin = value;// 设置结束时间的最小值为开始时间的值
                  $('#endtime').removeAttr('disabled');
                  $('#cdata').removeAttr('disabled');
                  $('#cdata').removeClass('layui-btn-disabled');
              }
            });
            // 结束时间选择器
            laydate.render({
              elem: '#endtime', // 指定元素
              type: 'time', // 只选择时间
              min: endDateMin,
              change: function(value, date){
                if (endDateMin !== '') {
                  // 比较结束时间是否大于开始时间
                  var start = new Date('1970/1/1 ' + endDateMin);
                  var end = new Date('1970/1/1 ' + value);
                  if (start - end >= 0) {
                    layer.msg('结束时间必须大于开始时间', {icon: 5});
                    return false;
                  }else{
                    $('#cdata').removeAttr('disabled');
                    $('#cdata').removeClass('layui-btn-disabled');
                  }
                }
              }
            });
            table.render({
            elem: '#datalist'
            , height: 'auto'
            , url: 'rulelist/' //数据接口
            , method: 'post'
            , page: true //开启分页
            , limit: 5
            , where:{id:1}
            , toolbar: '#toolbartop'
            , defaultToolbar: ['filter', 'exports', 'print']
            , cols: [[ //表头
                {field: 'zizeng', title: function(){ return lang.serial }, align: "center", fixwidth: true, width: 80, templet:'#zizeng'},
                {field: 'title', title: function(){ return lang.name }},
                {field: 'relate', title: function(){ return lang.gorun+'ID' }},
                {field: 'relatename', title: function(){ return lang.regula+lang.name }},
                {field: 'createtime', title: function(){ return lang.createtime }},
                {field: 'status', title: function(){ return lang.status },
                 templet: function(d) {
                       if (d.status == 1) {
                            return '<button class="layui-btn layui-btn-xs">'+lang.release+'</button>';
                        } else if (d.status == 2) {
                            return '<button class="layui-btn layui-btn-green layui-btn-xs">'+lang.finish+'</button>';
                        } else if (d.status == 3) {
                            return '<button class="layui-btn layui-btn-primary layui-btn-xs">'+lang.close+'</button>';
                        } else {
                            return '<button class="layui-btn layui-btn-danger layui-btn-xs">'+lang.wrelease+'</button>';
                        }
                      }},
                {fixed: '', title: function(){ return lang.operation }, width: 160, align: 'center', toolbar: '#bartool', hide:toolbar}
            ]],
            done: function() {
                            layer.closeAll('loading');
                            roleper.render({mid:23,per:[{sys:'rdel',method:'del'}],full:true});//law 设置长宽，full是否全屏，par父窗口打开
            }
            });
        
        table.on('toolbar(datalist)', function(obj){
          switch(obj.event){
            case 'redatalist':
              //执行重载
              table.reload('datalist');
            break;
            case 'reset':
              $.post('autorule/',{type:'2'},function(res){
                if(res.code == 200){
                  layer.msg(res.msg);
                  setTimeout(() => {
                    window.location.reload();
                    // xadmin.close();
                  }, 1000);
                }else{
                  layer.msg(res.msg);
                }
              })
            break;
          };
        });
        form.on('submit(autorule)', function (data) {
          allids=$('input[name="allids"]').val();
          ids=$('input[name="ids"]').val();
          if(allids.includes(ids)){
            layer.msg('规则已存在');
            return;
          }
          $.post('autorule/',data.field,function(res){
            if(res.code == 200){
              layer.msg(res.msg);
              setTimeout(() => {
                  window.location.reload();
                  // xadmin.close();
              }, 1000);
            }else{
              layer.msg(res.msg);
            }
          })
          return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        form.on('submit(submit)', function (data) {
          $.post('editrule',data.field,function(res){
              if(res.code == 200){
                  layer.msg(res.msg);
                  setTimeout(() => {
                      window.location.reload();
                      // xadmin.close();
                  }, 1000);
              }else{
                  layer.msg(res.msg);
              }
          })
          return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        $('#checkrule').on('click', function(){
        var data = 'checkrule';
        layer.open({
          type: 2,
          title: '<!--{$lang.page.public.select}-->',
          offset: '50px', 
          closeBtn: 1, //要显示关闭按钮
          anim: 2,
          shadeClose: true, //开启遮罩
          // moveOut: true,
          area: ['1024px', '700px'],
          content: 'checkrule/'
          ,resize:false
          ,maxmin: false //开启最大化最小化按钮
          ,success:function (layero, index) {
            var iframe = window['layui-layer-iframe'+index]; // 获取子页面的iframe
            iframe.child(data);// 向子页面的全局函数child传参

          }
        });
        window.ppp = function(value){
            if (value) {
              $('input[name="ids"]').val(value.join());
              $('#crule').removeAttr('disabled');
              $('#crule').removeClass('layui-btn-disabled');
            }
        }
      })            
    });
</script>
</body>
</html>

